from django.shortcuts import render, redirect
from django.http import JsonResponse, HttpResponse
from django.contrib.auth import login, logout
from .models import User
# Create your views here.


def user_login(request):
    if request.method == 'POST':
        form = request.POST
        username = form.get('username')
        password = form.get('password')
        user = User.objects.filter(username=username).first()
        if user.check_password(password):
            login(request, user)
            return redirect('/pic/pics')

    return render(request, 'user/login.html', {})
